define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'monitor/user/index',
                    add_url: 'monitor/user/add',
                    edit_url: 'monitor/user/edit',
                    del_url: 'monitor/user/del',
                    multi_url: 'monitor/user/multi',
                    table: 'wechat_user',
                }
            });

            var table = $("#table");
            var department_data = Config.department_data;
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'userid',
                sortName: 'userid',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'userid', title: __('Userid'),operate: 'LIKE %...%'},
                        {field: 'name', title: __('Name'),operate:'LIKE',placeholder: __('模糊查询')},
                        // {field: 'mobile', title: __('Mobile')},
                        {field: 'department', title: __('Department'),searchList:department_data,operate:'LIKE %...%'},
                        // {field: 'position', title: __('Position')},
                        // {field: 'gender', title: __('Gender')},
                        // {field: 'email', title: __('Email')},
                        // {field: 'enable', title: __('Enable')},
                        // {field: 'status', title: __('Status')},                        
                    ]
                ]
            });

            //  获取最新数据
            $("#get_user").click(function(){
                $.post('/api/ewechat/simplelist',function(json){
                    if(json.code == 1){
                        Backend.api.toastr.success(json.msg);
                        table.bootstrapTable('refresh', {});
                    }else{
                        Backend.api.toastr.error(json.msg);
                    }                   
                })
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});